﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;
using System.IO;
using System.Windows.Forms;

namespace weiqijiance.废气仪
{
    public class fqybass
    {
        public float m_fYaLi=0;
        public float m_fLamda = 0;
        public float m_fWenDu = 0;
        public float m_fyw = 0;
        public float m_fShiDu = 0;
        public float m_fO2 = 0;
        public float m_fCo = 0;
        public float m_fCo2 = 0;
        public int m_iNo = 0;
        public int m_iHc = 0;
        //public int m_iGasturn = 0;

        public bool m_fDLLYJ = false;//低流量报警
        public bool m_fxlbs = false;//泄露检测状态（是否检漏完成）
        public int m_fxl;//泄露检测标志（是否合格）
        public 温湿度大气压.wsddqybass objwsddqy;

        public SerialPort commex = new SerialPort();//废气仪串口

        public 转速仪.zsybass objzsy;
        public virtual bool openCOM(string sSet1)
        {
            string[] szbzlCOM = new string[5];
            if (sSet1.Length > 0)
                szbzlCOM = sSet1.Split(':');
            //打开串口
            commex.PortName = szbzlCOM[0];
            commex.BaudRate = Convert.ToInt32(szbzlCOM[1]);

            commex.NewLine = "/r/n";
            commex.RtsEnable = true;//根据实际情况吧。 
            commex.ReadTimeout = 300;//读取数据延时，避免读取不全数据

            if (szbzlCOM[3] == "0")
                commex.Parity = Parity.None;
            else
                commex.Parity = Parity.Even;
            // ////添加事件注册  
            //  comm.DataReceived += comm_Data;
            try
            {
                commex.Open();
            }
            catch (Exception)
            {
                //lzj20200706 MessageBox.Show(string.Format("{0}\n请检查电脑的串口故障", ex.Message));
                return false;
            }
            return true;
        }

        /// <summary>
        /// 发送指令到仪器
        /// </summary>
        /// <param name="cmd">通信命令
        /// 1:开始测量命令;
        /// 2:停止测量命令;
        /// 3:实时数据获取命令;
        /// 4:反吹;
        /// 5:调零命令;
        /// 6:实时状态获取命令;
        /// 7:背景空气测定命令;
        /// 8:环境空气测定命令;
        /// 9:HC残留测量;
        /// 10:泄漏检查;
        /// 11:设置调零气体命令;(预留)
        /// 12:尾气校准命令;(预留)
        /// 13:锁定键盘操作命令;
        /// 14:解锁键盘操作命令;
        /// 15:HC燃料设置命令;(预留)
        /// 16:设置点火数命令;(预留)
        /// 17:设置冲程数命令;(预留)
        /// 18:背景空气数据获取;
        /// 19:环境空气数据获取;
        /// 20:HC残留数据获取;
        ///21:管路压力标定命令;(预留)
        ///22:油温标定命令;(预留)
        ///23:自动调零设置命令;(预留)
        ///24:停止当前动作检查命令;(预留)
        ///25:抽气动作检查命令;(预留)
        ///26:抽环境空气动作检查命令;(预留)
        ///27:通零气动作检查命令;(预留)
        ///28:通校准气动作检查;(预留)
        /// 29:通检查气动作检查命令;(预留)</param>
        /// <returns></returns>
        public virtual bool SendDeviceCmd(int cmd)
        {
            if (cmd == 3)
            {
                m_fWenDu = objwsddqy.m_fWenDu;
                m_fShiDu = objwsddqy.m_fShiDu;
                m_fYaLi = objwsddqy.m_fYaLi;
            }
            return true;
        }
        //public List<byte> buffer = new List<byte>(4096);
        //void comGAS_DataReceived(object sender, SerialDataReceivedEventArgs e)
        //{

        //}

        public string syouwen = "";
        public string CO2_CY = "";
        public bool bfqyco2 = false;
        public void jcyq()
        {
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\检测要求设置.ini";
            string path1 = string.Format(@"{0}", path);
            iniclass objini = new iniclass();
            objini.Ini(path1);


            //CO2_CY = objini.ReadValue("设置", "柴油车CO2");
            //syouwen = objini.ReadValue("设置", "油温检测要求");

        }

            Random ran = new Random();
        public int getRandom(int imin, int imax)
        {
            return ran.Next(imin, imax);
        }
    }
}
